package com.cortex.pineapple.fetch;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;

import com.cortex.pineapple.fetch.RequestData.FILTER_TYPE.FILTER_VALUE;

public class RequestData {

	private String query;
	private int top;
	private int skip;
	private List<SOURCE_TYPE> sourcesType;
	private CATEGORY_FILTER_TYPE categoryFilter;
	private HashMap<FILTER_TYPE, FILTER_VALUE> filters;

	public RequestData(){
		// do nothing
	}
	public RequestData(String query, int count,int skip,CATEGORY_FILTER_TYPE filterType,
			HashMap<FILTER_TYPE, FILTER_VALUE> filters,List<SOURCE_TYPE> sourcesType) {
		this.query = query;
		this.top = count;
		this.skip = skip;
		this.categoryFilter = filterType;
		this.sourcesType = sourcesType;
		this.filters = filters;
	}
	public String getQuery() {
		return query;
	}
	public void setQuery(String query) {
		this.query = query;
	}
	public int getTop() {
		return top;
	}
	public void setTop(int top) {
		this.top = top;
	}
	public CATEGORY_FILTER_TYPE getCategoryFilterType() {
		return categoryFilter;
	}
	public void setCategoryFilterType(CATEGORY_FILTER_TYPE categoryFilter) {
		this.categoryFilter = categoryFilter;
	}
	public List<SOURCE_TYPE> getSourcesType() {
		return sourcesType;
	}
	public void setSourceType(List<SOURCE_TYPE> sourcesType) {
		this.sourcesType = sourcesType;
	}

	public int getSkip() {
		return skip;
	}
	public void setSkip(int skip) {
		this.skip = skip;
	}
	public HashMap<FILTER_TYPE, FILTER_VALUE> getFilters() {
		return filters;
	}
	public void setFilters(HashMap<FILTER_TYPE, FILTER_VALUE> filters) {
		this.filters = filters;
	}
	public enum CATEGORY_FILTER_TYPE{
		WEB,
		IMAGES,
		VIDEO,
		NEWS,
		COMPOSITE;

		static public String getCategoryFilterType(CATEGORY_FILTER_TYPE source){
			switch(source){
			case IMAGES:
				return "Image";
			case NEWS:
				return "News";
			case VIDEO:
				return "Video";
			case WEB:
				return "Web";
			case COMPOSITE:
				return "Composite";
			default:
				return "Web";

			}
		}
	}
	public enum SOURCE_TYPE{
		WEB,
		IMAGES,
		VIDEO,
		NEWS;

		static public String getSourceType(SOURCE_TYPE source){
			switch(source){
			case IMAGES:
				return "Image";
			case NEWS:
				return "News";
			case VIDEO:
				return "Video";
			case WEB:
				return "Web";
			default:
				return "Web";

			}
		}
		static public String getSourcesType(SOURCE_TYPE... sourcesType){
			StringBuilder sources = new StringBuilder();
			for (int i = 0; i < sourcesType.length; i++) {
				sources.append(getSourceType(sourcesType[i]));
				if(i<sourcesType.length - 1){
					sources.append("+");
				}
			}
			return sources.toString();
		}
		static public List<SOURCE_TYPE> getSourceType(String... sources){
			List<SOURCE_TYPE> sourcesType = new ArrayList<RequestData.SOURCE_TYPE>();			
			for (int i = 0; i < sources.length; i++) {
				if(sources[i].equals("web")){
					sourcesType.add(SOURCE_TYPE.WEB);
				}
				else if(sources[i].equals("images")){
						sourcesType.add(SOURCE_TYPE.IMAGES);
				}
				else if(sources[i].equals("videos")){
						sourcesType.add(SOURCE_TYPE.VIDEO);
				}
				else if(sources[i].equals("news")){
						sourcesType.add(SOURCE_TYPE.NEWS);
				}
			}
			return sourcesType;
		}
	}
	public enum FILTER_TYPE{
		FILE_TYPE,
		IMAGE_TYPE,
		IMAGE_SIZE,
		IMAGE_COLOR,
		IMAGE_PEOPLE,
		VIDEO_DATE,
		VIDEO_LENGTH,
		VIDEO_RESOLUTION,
		NEWS_DATE,
		NEWS_CATEGORY;

		static public String getValue(FILTER_TYPE filter){
			switch(filter){
			case FILE_TYPE:
				return "WebFileType";
			case IMAGE_COLOR:
				return "Color";
			case IMAGE_PEOPLE:
				return "Face";
			case IMAGE_SIZE:
				return "Size";
			case IMAGE_TYPE:
				return "image type";
			case NEWS_CATEGORY:
				return "NewsCategory";
			case VIDEO_DATE:
				return "video date";
			case VIDEO_LENGTH:
				return "Duration";
			case VIDEO_RESOLUTION:
				return "Resolution";
			default:
				return "";


			}
		}
		public enum FILTER_VALUE{
			// web
			DOC,
			XLS,
			PDF,
			TEXT,
			TXT,
			HTML,
			// images
			SMALL,
			MEDIUM,
			LARGE,
			BLACK_AND_WHITE,
			FACE,
			JPG, 
			GIF, 
			PNG, 
			BMP,
			// videos
			SHORT,
			LONG,
			LOW,
			HIGH,
			// news
			BUSINESS,
			ENTERTAIRMENT,
			HEALTH,
			POLITICS,
			SPORTS,
			US,
			WORLD,
			SIENCE_AND_TECHNOLOGY,
			SORT_BY_DATE;

			static public String getValue(FILTER_VALUE filterValue){
				switch(filterValue){
				case BUSINESS:
					return "rt_business";
				case DOC:
					return "doc";
				case ENTERTAIRMENT:
					return "rt_entertairment";
				case FACE:
					return "Aface";
				case BLACK_AND_WHITE:
					return "Amonochrome";
				case HEALTH:
					return "rt_health";
				case HIGH:
					return "Ahigh";
				case HTML:
					return "Ahtml";
				case LARGE:
					return "Alarge";
				case LONG:
					return "Along";
				case LOW:
					return "Alow";
				case MEDIUM:
					return "Amedium";
				case PDF:
					return "pdf";
				case POLITICS:
					return "rt_politics";
				case SHORT:
					return "Ashort";
				case SIENCE_AND_TECHNOLOGY:
					return "rt_sienceAndTechnology";
				case SMALL:
					return "Asmall";
				case SPORTS:
					return "rt_sports";
				case TEXT:
					return "text";
				case TXT:
					return "txt";
				case US:
					return "rt_us";
				case WORLD:
					return "rt_world";
				case XLS:
					return "xls";
				case JPG:
					return "jpg";
				case BMP:
					return "bmp";
				case PNG:
					return "png";
				case GIF:
					return "gif";
				case SORT_BY_DATE:
					return "date";
				default:
					return "";
				}
			}
			static public FILTER_VALUE getFilterValue(String value){

				value = value.toLowerCase(Locale.getDefault());
				if(value.contains("black and white")){
					return FILTER_VALUE.BLACK_AND_WHITE;
				}
				else if(value.contains("business")){
					return FILTER_VALUE.BUSINESS;
				}
				else if(value.contains("doc")){
					return FILTER_VALUE.DOC;
				}
				else if(value.contains("entertainment")){
					return FILTER_VALUE.ENTERTAIRMENT;
				}
				else if(value.contains("face")){
					return FILTER_VALUE.FACE;
				}
				else if(value.contains("health")){
					return FILTER_VALUE.HEALTH;
				}
				else if(value.contains("high")){
					return FILTER_VALUE.HIGH;
				}
				else if(value.contains("html")){
					return FILTER_VALUE.HTML;
				}
				else if(value.contains("large")){
					return FILTER_VALUE.LARGE;
				}
				else if(value.contains("long")){
					return FILTER_VALUE.LONG;
				}
				else if(value.contains("low")){
					return FILTER_VALUE.LOW;
				}
				else if(value.contains("medium")){
					return FILTER_VALUE.MEDIUM;
				}
				else if(value.contains("pdf")){
					return FILTER_VALUE.PDF;
				}
				else if(value.contains("politics")){
					return FILTER_VALUE.POLITICS;
				}
				else if(value.contains("short")){
					return FILTER_VALUE.SHORT;
				}
				else if(value.contains("sience and technology")){
					return FILTER_VALUE.SIENCE_AND_TECHNOLOGY;
				}
				else if(value.contains("small")){
					return FILTER_VALUE.SMALL;
				}
				else if(value.contains("sports")){
					return FILTER_VALUE.SPORTS;
				}
				else if(value.contains("text")){
					return FILTER_VALUE.TEXT;
				}
				else if(value.contains("txt")){
					return FILTER_VALUE.TXT;
				}
				else if(value.contains("us")){
					return FILTER_VALUE.US;
				}
				else if(value.contains("world")){
					return FILTER_VALUE.WORLD;
				}
				else if(value.contains("xls")){
					return FILTER_VALUE.XLS;
				}
				else if(value.contains("jpg")){
					return FILTER_VALUE.JPG;
				}
				else if(value.contains("bmp")){
					return FILTER_VALUE.BMP;
				}
				else if(value.contains("png")){
					return FILTER_VALUE.PNG;
				}
				else if(value.contains("gif")){
					return FILTER_VALUE.GIF;
				}
				else if(value.contains("sort by date")){
					return FILTER_VALUE.SORT_BY_DATE;
				}
				return null;
			}
		}
		
	}
}
